package com.example.service.impl.carecommunity;

import com.example.bean.carecommunity.Contract;
import com.example.bean.carecommunity.SafetySystem;
import com.example.bean.carecommunity.SheQujujia;
import com.example.bean.carecommunity.Vo.SafetySystemVo;
import com.example.mapper.carecommunity.SafetySystemMapper;
import com.example.service.carecommunity.SafetySystemService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SafetySystemServiceImpl implements SafetySystemService {
    @Autowired
    SafetySystemMapper mapper;

    @Override
    public PageInfo<SafetySystem> selectSafety(SafetySystemVo safetyvo) {
        Integer cp = safetyvo.getCurrentPage()==null?1:safetyvo.getCurrentPage();
        Integer ps = safetyvo.getPageSize()==null?10:safetyvo.getPageSize();
        PageHelper.startPage(cp,ps);
        PageInfo<SafetySystem> pageinfo = new PageInfo<SafetySystem>(mapper.selectSafety(safetyvo));
        return pageinfo;
    }

    @Override
    public List<String> selectNoid() {
        return mapper.selectNoid();
    }

    @Override
    public List<Contract> selectZhibiao(String id) {
        return mapper.selectZhibiao(id);
    }

    @Override
    public List<SheQujujia> getRizhaoJujia() {
        return mapper.getRizhaoJujia();
    }

    @Override
    public Integer addSafetySystem(SafetySystem safetySystem) {
        SheQujujia sheQujujia = mapper.selectJigouId(safetySystem.getRijianjujiaid());
        safetySystem.setJigouid(sheQujujia.getJigouId());
        safetySystem.setFlag(sheQujujia.getFlag());
        return mapper.addSafetySystem(safetySystem);
    }

    @Override
    public SafetySystem selectEditSafety(String noid) {
        return mapper.selectEditSafety(noid);
    }

    @Override
    public Integer editSafety(SafetySystem safetySystem) {
        Integer i = null;
        if(safetySystem.getIsxiaofang().equals("有")){
            i = mapper.editSafety(safetySystem);
        }
        if(safetySystem.getIsxiaofang().equals("无")){
            i = mapper.editSafetyi(safetySystem);
        }
        return i;
    }

    @Override
    public Integer deleteSafety(List<String> ids) {
        Integer i = null;
        for (String index : ids) {
            i = mapper.deleteSafety(index);
        }
        return i;
    }

    @Override
    public SafetySystem lookSafety(String noid) {
        return null;
    }

}
